#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: build_base.py 
@version:
@time: 2022/05/23 
"""
from TapClientCore.T01_init_conf.others import jenkins_config
from TapUtil.Tjenkins.tapjenkins import TapJenkins
from TapUtil.logfunc.logger import logger


class BuildBase:

    def __init__(self, env):
        self.config = jenkins_config.get(env)
        self.project = self.config.get('project')
        self.jenkins = TapJenkins(**self.config.get('auth'))
        self.args = '-sv'

    def update_args(self, new):
        self.args = new

    def get_kwargs(self, project):
        return self.jenkins.get_job(project).get_params_list()


class BuildBase2(BuildBase):
    def __init__(self, production='daas', env='local'):
        super(BuildBase2, self).__init__(env)
        self.current_project = self.project.get(production)

    def common_build(self, title, path):
        return {
            'case_name': title,
            'args': self.args,
            'case_path': path
        }

    def build(self, kwargs):
        logger.info(f'build {self.current_project} project')
        logger.info(f'build params {kwargs}')
        self.jenkins.build_job(self.current_project, kwargs)


if __name__ == '__main__':
    T = BuildBase2('local')
    res = T.get_kwargs('Daas2-dev-test')
    print(res)
    T.build(
        {
            'case_name': 'test for crontab',
            'args': '-sv',
            'case_path': 'Tests/test_v2/test_datasource/test_527.py'
        }
    )
